package com.bjpowernode.app;

import com.bjpowernode.annotation.Hzj;
import com.bjpowernode.beans.Stu;
import com.bjpowernode.services.MyIAImpA;
import com.bjpowernode.services.MyIAImpB;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class MyApp {
    public static void main(String[] args) throws NoSuchFieldException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {

        //获取的Stu类的类型Class对象
        Class<Stu> stuClass = Stu.class;
        //构造对象
        Constructor<Stu> constructor = stuClass.getConstructor();
        Stu stu = constructor.newInstance();
        //设置属性
        Field ia = stuClass.getDeclaredField("ia");
        //获取字段上的注解
        Hzj declaredAnnotation = ia.getDeclaredAnnotation(Hzj.class);
        //拿到注解上表达的信息
        Class value = declaredAnnotation.value();
        //根据表达按照实际场景进行编码【获取一个子类，并且实例化】
        Constructor constructor1 = value.getConstructor();
        Object o = constructor1.newInstance();
        ia.setAccessible(true);
        //这是字段具体值
        ia.set(stu,o);
        //调用方法
        Method play = stuClass.getMethod("play");
        play.invoke(stu);
    }
}
